(function ($) {
    $(function () {
        var defaults = {
            async: false,
            type: 'get',
            url: ROOT_PATH + "upms/manage/getMenus",
            success: function (data) {
                var Menus = [];
                if (data && data.length) {
                    $.each(data, function (i, menu) {
                        Menus.push(menu);
                    });
                    if (Menus.length > 0) {
                        var menusHtml = template("MenuTemp", {data: Menus});
                        $("#side-menu").append(menusHtml);
                    }
                }
            }
        }

        var methods = {
            init:function() {
                var buildMenu = function(){
                    $.Ajax(defaults);
                }
                return buildMenu();
            },
            initByAppName:function(appName) {
                var buildMenu = function(){
                    var extend = $.extend(defaults,{url:ROOT_PATH + "upms/manage/getMenusByAppName",data:{appName:appName}});
                    $.Ajax(extend);
                }
                return buildMenu();
            },
        }
        $.fn.Menu = function (method) {
            // 方法调用
            if (methods[method]) {
                return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
            } else if (typeof method === 'object' || !method) {
                return methods.init.apply(this, arguments);
            } else {
                $.error('Method' + method + 'does not exist on jQuery.niftySettings');
            }
        };

        //初始化
        methods.init();
    })
})(jQuery);